import pymssql, sys
import 笔趣阁 as bqg, pymssql as ms, MyClass as mc, BaseFunction as BF
import 搜搜小说网 as ss, 第二课堂 as xbqg


totalBook = 0
totalChapter = 0


def GetAllBooks():
    sql = "Select b.BID,b.Name,b.href,b.Author,b.UpdateTime,b.Source,COUNT(c.ID) Num  from BooksInfo as b,ChapterInfo " \
          "as c where b.BID = c.BID group by b.BID,b.Name,b.Author,b.UpdateTime,b.href,b.Source "
    # bc 里面全是 字典
    bc = BF.selectmssql(sql, (), **BF.sqlparms)
    for b in bc:
        Chapters = []
        if b['href'] == "":
            return 0
        # 根据原网址 爬取最新章节数
        Chapters = BF.check(b['href'])
        # 多余当前存储数 保存
        if len(Chapters) > b['Num']:
            print(b['Name'] + '，  ID=' + str(b['BID']))
            zjc = Chapters[b['Num']:]
            # 更新
            BF.Update(zjc, b['BID'], b['href'])


GetAllBooks()
input('按任意键结束')
